package com.lc.pianostudent.activity;

import android.os.Bundle;
import android.text.InputFilter;
import android.view.View;
import android.widget.TextView;

import com.lc.pianostudent.BaseApplication;
import com.lc.pianostudent.R;
import com.lc.pianostudent.conn.PostUpdateName;
import com.lc.pianostudent.conn.PostUploadAvatar;
import com.lc.pianostudent.fragment.MineFragment;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.glide.GlideLoader;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

/**
 * Created by Administrator on 2018/6/25.
 */

public class EditNicknameActivity extends BaseActivity{

    @BoundView(R.id.nickname_text) private TextView nickname_text;
    //修改昵称
    public PostUpdateName postUpdateName = new PostUpdateName(new AsyCallBack<PostUpdateName.PostUpdateNameInfo>(){

        @Override
        public void onSuccess(String toast, int type, Object o, PostUpdateName.PostUpdateNameInfo postUpdateNameInfo) throws Exception {
            UtilToast.show(toast);
            finish();

            try {
                    ((MineFragment.CallBack)getAppCallBack(MineFragment.class)).onRefresh();
                } catch (Exception e) {
                    e.printStackTrace();
                }

            try {
                    ((PersonInfoActivity.CallBack)getAppCallBack(PersonInfoActivity.class)).onRefresh();
                } catch (Exception e) {
                    e.printStackTrace();
                }
        }

        @Override
        public void onFail(String toast, int type) throws Exception {
            UtilToast.show(toast);
        }
    });

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit_nickname);

        setBackTrue();


        initView();
    }

    private void initView(){
        setTitleName("昵称");
        nickname_text.setText(getIntent().getStringExtra("nick"));
        nickname_text.setFilters(new InputFilter[]{new InputFilter.LengthFilter(6)});
        setRightName("保存", R.color.textBlack_2e2e2e, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                postUpdateName.user_id = BaseApplication.BasePreferences.readUID();
                postUpdateName.text = nickname_text.getText().toString().trim();
                postUpdateName.execute();
            }
        });
    }
}
